home *** CD-ROM | disk | FTP | other *** search
/ Group 42-Sells Out! - The Information Archive / Group 42 Sells Out (Group 42) (1996).iso / crypto / rsan4pst.txt < prev    next >
Text File  |  1995-11-01  |  3KB  |  88 lines

  1. <title>Original post, on cypherpunks</title>
  2. <listing>
  3. Path: hks.net!news-mail-gateway!toad.com!owner-cypherpunks
  4. From: aba@atlas.ex.ac.uk
  5. Newsgroups: hks.lists.cypherpunks
  6. Subject: perl hackery, export-a-crypt-system
  7. Date: 9 Mar 1995 04:06:20 -0500
  8. Lines: 76
  9. Sender: root@bb.hks.net
  10. NNTP-Posting-Host: bb.hks.net
  11.  
  12.  
  13. Heres a bit of perl code which implements RSA encryption and
  14. decryption and is small enough to use for a signature:
  15.  
  16. -------------------------------------8<-------------------------------------
  17. #!/usr/local/bin/perl -- export-a-crypto-system sig, RSA in 5 lines of PERL:
  18. ($s,$k,$n)=@ARGV;$w=length$n;$k="0$k"if length($k)&1;$n="0$n",$w++if$w&1;die
  19. "$0 -d|-e key mod <in >out\n"if$s!~/^-[de]$/||$#ARGV<2;$v=$w;$s=~/d/?$v-=2:
  20. $w-=2;$_=unpack('B*',pack('H*',$k));s/^0*//g;s/0/d*ln%/g;s/1/d*ln%lm*ln%/g;
  21. $c="1${_}p";while(read(STDIN,$m,$w/2)){$m=unpack("H$w",$m);chop($a=
  22. `echo 16o16i\U$m\Esm\U$n\Esn$c|dc`);print pack('H*','0'x($v-length$a).$a);}
  23. -------------------------------------8<-------------------------------------
  24.  
  25. It has usable speed even for 512 bit keys, though its not as fast as
  26. PGP.  It uses repeated modulus on exponentiation to achieve usable
  27. performance, you could probably make it a line shorter without this
  28. optimisation.  It uses dc for bignums (you should be able to spot the
  29. `echo blah|dc` on the last line).
  30.  
  31. Heres a few keys you can try out 
  32.  
  33. 8bits:
  34. e=11
  35. d=ac1
  36. n=ca1
  37.  
  38. 32 bits:
  39. e=10001
  40. d=ac363601
  41. n=1967cb529
  42.  
  43. 128 bits:
  44. e=10001
  45. d=135b03530e94874283f0f0000ffff0001
  46. n=24000c6c9620886831124848640044901
  47.  
  48. 512 bits:
  49. e=10001
  50. d=62a03c0df0b96335047a12923a7d20bc2b7bb07c59aba2c4b094fc7d54392e8a2e7606cb5d574407640f4bb4e0ea6aeb7fff0000ffff0000ffff0000ffff0001
  51. n=12004001208404a43f00502200b204602600c00001da894922433e4601a2c85024024001418004602404240109301008140000000142404002010000000000001
  52.  
  53. To test, just save it as file "rsa", then do:
  54.  
  55. % chmod 700 rsa
  56. % echo "squeamish ossifrage" | rsa -e 11 ca1 > msg.rsa
  57. % rsa -d ac1 ca1 < msg.rsa
  58.  
  59. I wonder how good your chances of getting prosecuted under ITAR for
  60. having the above as a signature as an Amerikan citizen are :-) If
  61. challenged for exporting it you could defend yourself by saying you
  62. could have written it down on a piece of paper and snail mailed it
  63. which would presumably be legal?  Or read it over the phone?
  64.  
  65. Another use I thought of is an auto-reply block, ie the rsa code with
  66. your public key hard-coded into it:
  67.  
  68. -------------------------------------8<-------------------------------------
  69. #!/usr/local/bin/perl -- auto-encrypt-reply sig, RSA in 5 lines of perl:
  70. $n="012004001208404a43f00502200b204602600c00001da894922433e4601a2c8502402400".
  71. "1418004602404240109301008140000000142404002010000000000001";$/=0;$f=<STDIN>;
  72. $_="10000000000000001";s/0/d*ln%/g;s/1/d*ln%lm*ln%/g;$c="${_}p";
  73. for(;$i<length$f;$i+=64){$m=unpack("H128",substr($f,$i,128));chop($a=
  74. `echo 16o16i\U$m\Esm\U$n\Esn1$c|dc`);print pack('H*','0'x(130-length$a).$a);}
  75. -------------------------------------8<-------------------------------------
  76.  
  77. Any body can then encrypt a reply to you by saving and running the
  78. perl code, without needing PGP installed on their system.
  79.  
  80. Suggestions on any perl hackery to further shorten the code gratefully
  81. accepted.
  82.  
  83. Adam
  84.  
  85. _________________________________________________________________________
  86. email:aba@dcs.ex.ac.uk     http://dcs.ex.ac.uk/~aba/     pgp-key:556A4A67
  87. </listing>
  88.